package com.itheima.controller;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckGroupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/checkgroup")
@Slf4j
public class CheckGroupController {
    @Autowired
    private CheckGroupService checkGroupService;
    /*新增检查组*/
    @PostMapping("/add/{checkitemIds}")
    public Result add(@RequestBody CheckGroup checkGroup,@PathVariable List<Long> checkitemIds){
        log.info("新增检查项：{}", checkGroup);
        checkGroupService.add(checkGroup,checkitemIds);
        return new Result(true, MessageConstant.ADD_CHECKGROUP_SUCCESS,null);
    }
    /*删除检查组*/
    @GetMapping("/deleteById")
    public Result deleteById(Long id){
        log.info("删除检查项id：{}", id);
        checkGroupService.deleteById(id);
        return new Result(true,MessageConstant.QUERY_CHECKGROUP_SUCCESS,null);
    }
    /*根据套餐id查询检查组id*/
    @GetMapping("/findCheckGroupIdsBySetmealId")
    public Result findCheckGroupIdsBySetmealId(Long setmealId){
        List<String> list=checkGroupService.findCheckGroupIdsBySetmealId(setmealId);
        return new Result(true,MessageConstant.QUERY_CHECKGROUP_SUCCESS,list);
    }
    /*分页查询*/
    @PostMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        log.info("分页查询：{}", queryPageBean);
        PageResult pageResult = checkGroupService.findPage(queryPageBean);
        return pageResult;
    }
    /*修改检查组*/
    @PostMapping("/edit/{checkitemIds}")
    public Result edit(@RequestBody CheckGroup checkGroup,@PathVariable List<Long> checkitemIds){
        log.info("修改检查项：{}", checkGroup);
        checkGroupService.edit(checkGroup,checkitemIds);
        return new Result(true,MessageConstant.EDIT_CHECKGROUP_SUCCESS,null);
    }
    /*查询所有检查组*/
    @GetMapping("/findAll")
    public Result findAll(){
        List<CheckGroup> list=checkGroupService.findAll();
        return new Result(true,MessageConstant.QUERY_CHECKGROUP_SUCCESS,list);
    }
    /*根据id查询检查组*/
    @GetMapping("/findById")
    public Result findById(Long id){
        CheckGroup checkGroup=checkGroupService.findById(id);
        return new Result(true,MessageConstant.QUERY_CHECKGROUP_SUCCESS,checkGroup);
    }
}
